/**
 * 资讯服务模块路径导入辅助 - 统一配置入口模式
 */

// 导入路径解析器
const pathResolver = require('../../../config/path_resolver.js');

// 默认配置
const defaultProjectSetting = { 
  NEWS_CATE: [] 
};

// 默认模块实现
const defaultModules = {
  cloudHelper: {
    callCloud: async () => ({}),
    callCloudSumbit: async () => ({})
  },
  dataHelper: {
    formatNumber: (n) => n,
    getDataArr: (arr) => arr || []
  },
  timeHelper: {
    time: () => new Date().toISOString(),
    timestamp: () => Date.now()
  }
};

// 尝试导入必要的依赖 - 使用静态路径和try-catch
let projectSetting = defaultProjectSetting;
let cloudHelper = defaultModules.cloudHelper;
let dataHelper = defaultModules.dataHelper;
let timeHelper = defaultModules.timeHelper;

// 尝试加载projects_config.js
try {
  // 第一个可能的路径
  projectSetting = require('../../../config/projects_config.js');
  console.log('[news/path_import.js] 从 ../../../config/projects_config.js 加载项目配置成功');
} catch (e1) {
  console.warn('[news/path_import.js] 从 ../../../config/projects_config.js 加载失败', e1.message);
  
  try {
    // 第二个可能的路径
    projectSetting = require('../../../../config/projects_config.js');
    console.log('[news/path_import.js] 从 ../../../../config/projects_config.js 加载项目配置成功');
  } catch (e2) {
    console.warn('[news/path_import.js] 从 ../../../../config/projects_config.js 加载失败', e2.message);
    
    try {
      // 第三个可能的路径
      projectSetting = require('../../../../../config/projects_config.js');
      console.log('[news/path_import.js] 从 ../../../../../config/projects_config.js 加载项目配置成功');
    } catch (e3) {
      console.error('[news/path_import.js] 所有路径加载项目配置均失败，使用默认配置');
      // 使用默认配置
    }
  }
}

// 尝试加载cloud_helper.js
try {
  cloudHelper = require('../../../helpers/cloud_helper.js');
  console.log('[news/path_import.js] 从项目目录加载cloud_helper成功');
} catch (e1) {
  try {
    cloudHelper = require('../../../../helpers/cloud_helper.js');
    console.log('[news/path_import.js] 从上层目录加载cloud_helper成功');
  } catch (e2) {
    try {
      cloudHelper = require('../../../../../helpers/cloud_helper.js');
      console.log('[news/path_import.js] 从根目录加载cloud_helper成功');
    } catch (e3) {
      console.error('[news/path_import.js] 所有路径加载cloud_helper均失败，使用默认实现');
      // 使用默认实现
    }
  }
}

// 尝试加载data_helper.js
try {
  dataHelper = require('../../../helpers/data_helper.js');
  console.log('[news/path_import.js] 从项目目录加载data_helper成功');
} catch (e1) {
  try {
    dataHelper = require('../../../../helpers/data_helper.js');
    console.log('[news/path_import.js] 从上层目录加载data_helper成功');
  } catch (e2) {
    try {
      dataHelper = require('../../../../../helpers/data_helper.js');
      console.log('[news/path_import.js] 从根目录加载data_helper成功');
    } catch (e3) {
      console.error('[news/path_import.js] 所有路径加载data_helper均失败，使用默认实现');
      // 使用默认实现
    }
  }
}

// 尝试加载time_helper.js
try {
  timeHelper = require('../../../helpers/time_helper.js');
  console.log('[news/path_import.js] 从项目目录加载time_helper成功');
} catch (e1) {
  try {
    timeHelper = require('../../../../helpers/time_helper.js');
    console.log('[news/path_import.js] 从上层目录加载time_helper成功');
  } catch (e2) {
    try {
      timeHelper = require('../../../../../helpers/time_helper.js');
      console.log('[news/path_import.js] 从根目录加载time_helper成功');
    } catch (e3) {
      console.error('[news/path_import.js] 所有路径加载time_helper均失败，使用默认实现');
      // 使用默认实现
    }
  }
}

// 导出所有模块
module.exports = {
  pathResolver,
  projectSetting,
  cloudHelper,
  dataHelper,
  timeHelper
}; 